#include "MFrame.h"
#include "CFrame.h"


#include "xpm/sticky.xpm"
#include "xpm/question.xpm"

//===========================================================//
//CFrame(Child frame)
//===========================================================//

BEGIN_EVENT_TABLE(CFrame, wxPanel)
	EVT_PAINT(CFrame::OnPaint)
END_EVENT_TABLE()


CFrame::CFrame()
{

}

CFrame::CFrame(wxWindow * parent, wxWindowID id, bool has_toolbar)
{
	Create(parent, id, has_toolbar);
}

bool CFrame::Create(wxWindow * parent, wxWindowID id, bool has_toolbar)
{
	bool res = wxPanel::Create(parent, id, wxDefaultPosition, wxDefaultSize, wxCLIP_CHILDREN | wxFULL_REPAINT_ON_RESIZE );
	if(res)
	{
		m_parent = parent;
		m_ToolBar = NULL;
		m_HasToolBar = has_toolbar;
		//InitControls();
	}
	return res;
}
void CFrame::CreateControls()
{
	//virual
}
void CFrame::InitControls()
{
	//SetSizer(new wxBoxSizer(wxVERTICAL));

	//wxLogWarning(wxString::Format(_("ID: %d"),GetId()));

	//Connect(wxID_ANY, wxEVT_ACTIVATE, wxActivateEventHandler(CFrame::OnActivated));
	//Connect(wxEVT_ACTIVATE, wxActivateEventHandler(CFrame::OnActivated), NULL, this);
	//Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(CFrame::OnActivated), NULL, this);
	//m_ToolBar = CreateToolBar(wxTB_FLAT|wxTB_NODIVIDER, wxID_ANY);
	//if(m_ToolBar)
	//	GetSizer()->Add(m_ToolBar, 0, wxGROW);
	

	
}
void * CFrame::GetParent()
{
	return wxDynamicCast(m_parent, MFrame);
}


wxToolBar * CFrame::CreateToolBar(long style, wxWindowID winid)
{
	if(!m_ToolBar && m_HasToolBar)
	{
		m_ToolBar = new wxToolBar(this, winid, wxDefaultPosition,
			wxDefaultSize, style);
		//wxBitmap bmp;
		for(int i = 0; i < 1; i++)
		{
			
			wxWindowID id = GPW()->_generate_gui_id();
			m_ToolBar->AddTool(id, wxBitmap(16,16), wxString::Format(wxT("Tool %i"), i));
			Connect(id, wxEVT_COMMAND_MENU_SELECTED,
					wxCommandEventHandler(CFrame::OnToolButton));
		}
		m_ToolBar->Realize();
	}
	return m_ToolBar;
}

wxToolBar * CFrame::GetToolBar() const
{
	return m_ToolBar;
}

void CFrame::OnToolButton(wxCommandEvent & event)
{
	wxMessageBox(wxString::Format(_("Button %u pressed"), event.GetId()));
}

void CFrame::OnActivated(wxActivateEvent & event)//
{
	wxMessageBox("active!");
	//wxLogError(wxT("New Image note created with id : %d"), GetId());
	wxLogMessage(wxString::Format(_("Active note is: %d)"), GetId()));
	//wxLogWarning(wxT("New Image note created with id : %d"), GetId());
}


void CFrame::OnPaint(wxPaintEvent &event)
{
	//virtual
}

void CFrame::OnExit( wxEvent& WXUNUSED(event) )
{
	wxMessageBox("oh, no ....");
}

//===========================================================//
//AUI_CFrame(Child frame) with AUI styles
//===========================================================//


BEGIN_EVENT_TABLE(AUI_CFrame, CFrame)
	EVT_PAINT(AUI_CFrame::OnPaint)
END_EVENT_TABLE()

bool AUI_CFrame::Create(wxWindow * parent, wxWindowID id, bool has_toolbar)
{
	if(CFrame::Create(parent, id, has_toolbar))
	{
		m_FrameManager = new wxAuiManager;
		m_FrameManager->SetManagedWindow(this);

		//panel = new wxPanel(this, wxID_ANY);
		this->SetBackgroundColour(wxColour(245, 245, 245));

		//m_FrameManager->AddPane(panel, wxAuiPaneInfo().Name(wxT("CenterPane")).CenterPane());
		//GPW()->_register_gui_item(panel, wxT("CenterPane_"), wxAuiPaneInfo().CenterPane(),
			//wxT(""), GUII::PANEL, false, GetFManager());
		 
		
		//=============Add toolbar ====================================================================//
	
		//wxToolBar * toolBar = CreateToolBar(wxTB_FLAT|wxTB_NODIVIDER, wxID_ANY);
		//if(toolBar)
			;//GPW()->_register_gui_item(toolBar, wxT("ToolBar"), wxAuiPaneInfo().ToolbarPane().Top()
			//, wxT("Sub tool bar"), GUII::TOOLBAR, true, GetFManager());

		//=============Add center panel=================================================================//
		
		
		CreateControls();
		return true;
	}
	return false;
}

AUI_CFrame::~AUI_CFrame()
{
	if(m_FrameManager)
		m_FrameManager->UnInit();
}

void AUI_CFrame::CreateControls()
{

}

wxPanel * AUI_CFrame::GetPanel()
{
	return panel;
}

wxAuiManager * AUI_CFrame::GetFManager()
{
	return m_FrameManager;
}

void AUI_CFrame::OnPaint(wxPaintEvent &event)
{
	//do somwthing...
}